package com.sdk.util.phone;

import android.content.Context;
import android.net.Uri;
import android.provider.Browser;
import android.provider.SearchRecentSuggestions;
import android.text.ClipboardManager;

public class HistoryCleanUtil {

	private static HistoryCleanUtil sHistoryCleanUtil;

	private HistoryCleanUtil() {
	}

	public HistoryCleanUtil getInstance() {
		if (null == sHistoryCleanUtil) {
			sHistoryCleanUtil = new HistoryCleanUtil();
		}
		return sHistoryCleanUtil;
	}

	/**
	 * 清除Clipboard上面的内容
	 * 
	 * @param context
	 */
	public void cleanClipboard(Context context) {
		ClipboardManager clipboardManager = (ClipboardManager) context
				.getSystemService(Context.CLIPBOARD_SERVICE);
		clipboardManager.setText("");
	}

	/**
	 * 清除游览器的记录
	 * 
	 * @param context
	 */
	public void cleanGoogleBrower(Context context) {
		Browser.clearHistory(context.getContentResolver());
		Browser.clearSearches(context.getContentResolver());
	}

	/**
	 * 清除GmailSearch总得记录
	 * 
	 * @param context
	 */
	public void cleanGmailSearchRecorder(Context context) {
		try {
			new SearchRecentSuggestions(context,
					"com.google.android.gmail.SuggestionProvider", 1)
					.clearHistory();
			return;
		} catch (Exception localException) {
		}
	}

	/**
	 * 清除GoogleMapsearch中的数据
	 * 
	 * @param context
	 */
	public void cleanGoogleMapsSearchRecorder(Context context) {
		try {
			new SearchRecentSuggestions(context,
					"com.google.android.maps.SearchHistoryProvider", 1)
					.clearHistory();
			Uri localUri = Uri
					.parse("content://com.google.android.maps.SearchHistoryProvider/history");
			context.getContentResolver().delete(localUri, null, null);
		} catch (Exception localException) {
		}
	}

	/**
	 * 清除Google Market中的数据
	 * 
	 * @param context
	 */
	public void cleanMarketSearchRecorder(Context context) {
		try {
			new SearchRecentSuggestions(context,
					"com.android.vending.SuggestionsProvider", 1)
					.clearHistory();
		} catch (Exception localException) {
		}
	}
}
